import os
import sys
import subprocess

# 确保在正确的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
print(f"当前工作目录: {current_dir}")

# 安装依赖（如果需要）
requirements_file = os.path.join(current_dir, "requirements.txt")
if os.path.exists(requirements_file):
    print(f"正在安装依赖: {requirements_file}")
    subprocess.run(
        [sys.executable, "-m", "pip", "install", "-r", requirements_file,
         "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"]
    )

# 直接启动uvicorn服务
print("正在启动后端服务...")
subprocess.run(
    [sys.executable, "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
)